package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateAccountRolesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewUpdateAccountRolesLogic 更新账户角色关系
func NewUpdateAccountRolesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAccountRolesLogic {
	return &UpdateAccountRolesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateAccountRolesLogic) UpdateAccountRoles(req *types.UpdateAccountRolesRequest) error {
	_, err := l.svcCtx.AuthRoleRpc.UpdateAccountRoles(l.ctx, &v1.UpdateAccountRolesRequest{
		AccountId:   req.AccountId,
		RoleIds:     req.RoleIds,
		AccountType: v1.AccountType(req.AccountType),
	})

	return err
}
